package hari2.latihan;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Person implements Comparable{
	private long id;
	private String name;
	private String phone;
	
	public Person() {}
	public Person(int id, String name, String phone) {
		this.id = id;
		this.name = name;
		this.phone = phone;
	}
	
	public String toString() {
		return name + "\t" + phone;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public static void main(String[] args) {
		Person pTom = new Person(3, "Tom", "888-888");
		Person pAdi = new Person(2, "Adi", "123-456");
		Person pRudi = new Person(1, "Rudi", "0808-0808");
		
		List people = new ArrayList();
		people.add(pTom);
		people.add(pAdi);
		people.add(pRudi);
		
		System.out.println("bfore sort: " + people);
		
		Collections.sort(people); // ? ART / 018
		
		System.out.println("after sort: " + people);
	}
	@Override
// id as comparator	
	
//	public int compareTo(Object obj) {
//		Person prs = (Person) obj;
//		if (this.id < prs.id) {
//			return -1;
//		} else if (this.id > prs.id) {
//			return 1;
//		}
//		return 0;
//	}
	
// name as comparator
	public int compareTo(Object obj) {
		Person prs = (Person) obj;
		
			return this.name.compareTo(prs.name);
		
	}
}
